<template>
  <div>
    <el-dialog
      v-el-drag-dialog
      title="提瓶"
      :visible.sync="visible"
      width="400px"
      append-to-body
      @closed="reset"
    >
      <el-form ref="dataForm" class="form" :model="dataForm" label-width="100px" :rules="rules" label-position="right">
        <el-form-item label="责任机构:" prop="orgSNNo">
          <el-tree-select
            v-model="dataForm.ckOrgSNNo"
            :clearable="true"
            class="tree-select"
            :popover-width="360"
            :disabled="true"
            :select-params="{
              clearable: true,
              placeholder: '请选择',
            }"
            :tree-params=" {
              'expand-on-click-node': false,
              'highlight-current': true,
              'filterable': true,
              props:{
                value:'orgSNNo',
                label: 'orgName',
                disabled: 'disabled',
              },
              data: treeData
            }"
          />
        </el-form-item>
        <el-form-item label="处理人:" prop="ownerId">
          <el-select v-model="dataForm.ownerId" placeholder="请选择">
            <el-option v-for="(v,userId) in depReceiver" :key="userId" :label="v.userName" :value="v.userId" />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirm">确定</el-button>
        <el-button @click="reset">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { depositTakeBottle, csDeliverUserList } from '@/api'
  export default {
    name: '',
    components: {},
    props: {
      treeData: {
        type: Array,
        required: true
      }
    },
    data() {
      return {
        dataForm: {
          ckOrgSNNo: null,
          ownerId: null
        },
        visible: false,
        depReceiver: [],
        rules: {
          ownerId: [{ required: true, message: '请选择处理人', trigger: 'change' }]
        }
      }
    },
    computed: {},
    created() {
    },
    mounted() {},
    methods: {
      // 处理人
      async payee(orgId, orgSNNo) {
        const params = {
          deliveryOrgId: orgId,
          deliveryOrgSNNo: orgSNNo
        }
        const res = await csDeliverUserList(params)
        this.depReceiver = res.data
      },
      open(row) {
        return new Promise(resolve => {
          this.resolve = resolve
          this.dataForm.ckOrgSNNo = row.ckOrgSNNo
          this.dataForm.ckOrgId = row.ckOrgId
          this.dataForm.ckOrgName = row.ckOrgName
          this.dataForm.depositCode = row.depositCode
          console.log('row', row)
          this.payee(this.dataForm.ckOrgId, this.dataForm.ckOrgSNNo)
          this.visible = true
        })
      },
      confirm() {
        this.$refs.dataForm.validate(async(valid) => {
          if (!valid) return
          depositTakeBottle({ depCode: this.dataForm.depositCode, ownerId: this.dataForm.ownerId }).then(res => {
            this.resolve()
            this.$message({
              title: '提示',
              message: '操作成功',
              type: 'success',
              duration: 2000
            })
            this.visible = false
            this.$emit('upDataTable')
          })
        })
      },
      reset() {
        this.dataForm = {
          ckOrgSNNo: null,
          ownerId: null
        }
        this.$refs.dataForm.resetFields()
        this.visible = false
      }
    }
  }

</script>
<style lang='scss' scoped>
</style>
